package com.jmpt.fangbohui.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.bean.BrokerHouseBean;
import com.jmpt.fangbohui.utils.ImageLoaderHelper;

public class BrokerHouseListAdapter extends BaseAdapter {
	
	private Context mContext;
	public List<BrokerHouseBean> houseList = new ArrayList<BrokerHouseBean>();

    public BrokerHouseListAdapter(Context context) {
    	this.mContext = context;
    }
	@Override
	public int getCount() {
		return houseList.size();
	}

	@Override
	public Object getItem(int position) {
		return houseList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//TODO 填充旧房条目
		if (convertView == null) {
			convertView = View.inflate(mContext, R.layout.item_list_oldhouse, null);
        }
        Holder holder = getHolder(convertView);
        BrokerHouseBean bean = houseList.get(position);
        ImageLoaderHelper.displayImage(bean.H_SmallPic, holder.housePhoto);
        holder.houseTitle.setText(bean.H_Title);
        holder.houseRoomAndHall.setText(bean.H_Room +"房" + bean.H_Hall + "厅");
        holder.houseProportion.setText(bean.H_MJ + "平米");
        holder.houseTotalPrice.setText(String.valueOf(bean.H_SalePrice + bean.price_type));
        holder.houseAddress.setText(bean.H_DZ);
        if(!TextUtils.isEmpty(bean.ZXName)){
        	holder.houseFitment.setVisibility(View.VISIBLE);
        	holder.houseFitment.setText(bean.ZXName);
        }else{
        	holder.houseFitment.setVisibility(View.INVISIBLE);
        }
        return convertView;

    }

    private Holder getHolder(final View view) {
        Holder holder = (Holder) view.getTag();
        if (holder == null) {
            holder = new Holder(view);
            view.setTag(holder);
        }
        return holder;
    }


    private class Holder {
        public ImageView housePhoto;
        public TextView houseTitle;
        public TextView houseRoomAndHall;
        public TextView houseProportion;
        public TextView houseTotalPrice;
        public TextView houseAddress;
        public TextView houseFitment; //装修
        public Holder(View view) {
        	housePhoto = (ImageView) view.findViewById(R.id.iv_oldhouse_item_photo);
        	houseTitle = (TextView) view.findViewById(R.id.tv_oldhouse_item_title);
        	houseRoomAndHall = (TextView) view.findViewById(R.id.tv_oldhouse_item_roomAndHall);
        	houseProportion = (TextView) view.findViewById(R.id.tv_oldhouse_item_proportion);
        	houseTotalPrice = (TextView) view.findViewById(R.id.tv_oldhouse_item_totalPrice);
        	houseAddress = (TextView) view.findViewById(R.id.tv_oldhouse_item_addr);
        	houseFitment = (TextView) view.findViewById(R.id.tv_oldhouse_item_fitment);
        }
    }
}
